package com.cf.back.permission.controller;

import com.cf.crudweb.controller.CommonController;
import com.cf.user.permission.model.SystemRole;
import com.cf.user.permission.service.SystemRoleService;
import com.cf.vo.ResponseVo;
import com.cf.web.RequiredLogin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * game-server-RoleController
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/31 上午 10:37
 */
@RequiredLogin
@RequestMapping("/systemRole")
public class SystemRoleController extends CommonController<SystemRole, SystemRoleService> {
    @Override
    protected String getPageDir() {
        return "systemRole";
    }

    @ResponseBody
    @RequestMapping("/userRoles")
    public ResponseVo<List<Long>> userRoles(long userId) {
        List<Long> userRoleId = this.getService().userRoles(userId);
        return ResponseVo.success(userRoleId, "获取用户角色成功！");
    }


    @ResponseBody
    @RequestMapping(value = "/updateUserRoles", method = {RequestMethod.POST})
    public ResponseVo<Boolean> userRoles(long userId, @RequestBody List<Long> roleIds) {
        this.getService().updateUserRoles(userId, roleIds);
        return ResponseVo.success(true, "获取用户角色成功！");
    }

}
